//全局变量, 本身就是被线程共享的
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

int g_val = 100;

void* threadRoutine(void* args)
{
    string name = static_cast<const char* >(args);
    while(true)
    {
        cout << "I am new thread" << ", thread name: " << name << ", g_val:" << g_val 
            << ", &g_val" << &g_val << endl;
        g_val++;
        sleep(1);
    }
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRoutine, (void*)"thread-1");
    while(true)
    {
        cout << "I am main thread" <<  ", g_val:" << g_val 
            << ", &g_val" << &g_val << endl;
        sleep(1);
    }

    pthread_join(tid, nullptr); 
    return 0;
}